package com.jiepos.mpos.biz.code.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.code.service.NoticeInfService;
import com.jiepos.mpos.common.entity.App_Ins_InfEntity;
import com.jiepos.mpos.common.entity.App_Notice_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;



/**
 *
 *
 * <p>标题: —— 系统参数控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @author 余翼膑
 * @version 1.0
 * @since 2018年01月24日
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("notice")
public class NoticeInfController extends BaseController {

    @Autowired
    private NoticeInfService noticeInfService;


    /**
     * 进入通知公告页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getNoticeInfList.do")
    public ModelAndView getNoticeInfList(HttpServletRequest request, HttpServletResponse response, Pagination pagination){

        ModelAndView model = new ModelAndView("/module/code/notice/notice_list");
        return super.getDetail(request, response, model);
    }

    /**
     * 查询通知公告列表信息json数据
     * @param pagination
     * @param appNoticeInfEntity
     * @return
     */
    @RequestMapping("/noticeInfListJson.do")
    public @ResponseBody
    Map getNoticeListJson(HttpServletRequest request, Pagination pagination, App_Notice_InfEntity appNoticeInfEntity, App_Ins_InfEntity appInsInfEntity){
        return noticeInfService.noticeInfListJson(request,pagination, appNoticeInfEntity,appInsInfEntity);
    }

    /**
     * 进入通知公告详细页面
     * @param request
     * @param response
     * @param pagination
     * @param notice_uuid
     * @return
     */
    @RequestMapping("/getNoticeInfDetail.do")
    public ModelAndView getNoticeInfDetail(HttpServletRequest request, HttpServletResponse response,
                                        Pagination pagination,String notice_uuid) {
        ModelAndView model = new ModelAndView("/module/code/notice/notice_detail");
        // 菜单编码
        Map infEntity = noticeInfService.getNoticeInfById(notice_uuid);
        model.addObject("infEntity", infEntity);
        return super.getDetail(request, response, model);
    }

    /**
     * 保存通知公告信息
     * @param request
     * @param response
     * @param appNoticeInfEntity
     * @return
     */
    @RequestMapping("/saveNoticeInfDetail.do")
    public ModelAndView saveNoticeInfDetail(HttpServletRequest request, HttpServletResponse response, App_Notice_InfEntity appNoticeInfEntity) {

        noticeInfService.saveNoticeInf(appNoticeInfEntity, super.getLoginUser(request, response));
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getNoticeInfList.do"), map);
    }

    /**
     * 更新发布状态
     * @param request
     * @param response
     * @param notice_uuids
     * @return
     */
    @RequestMapping("/updNoticeInfDetail.do")
    @ResponseBody
    public Map<String, Object> updNoticeInfDetail(HttpServletRequest request, HttpServletResponse response, String notice_uuids, String publish_st ) {
        noticeInfService.updNoticeInfDetail(notice_uuids,publish_st, super.getLoginUser(request, response));
        return new HashMap<>();
    }

    /**
     * 首页通知公告详情
     * @param request
     * @param uuid
     * @return
     */
    @RequestMapping("/detailNotice.do")
    @ResponseBody
    public Map<String, Object> detailNoticeForHomePage(HttpServletRequest request, String uuid){
    	return noticeInfService.findByUuidForHomePage(uuid);
    }
}
